package com.example.lets;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
  
public class SelectPicPopupWindow extends PopupWindow {  
  
  
    private LinearLayout btn_take_photo, btn_pick_photo, btn_cancel;
    private View mMenuView;  
  
    public SelectPicPopupWindow(Activity context,OnClickListener itemsOnClick) {  
        super(context);  
        
        LayoutInflater inflater = (LayoutInflater) context  
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);  
        mMenuView = inflater.inflate(R.layout.select_pic_popup_window, null);  
        btn_take_photo = (LinearLayout) mMenuView.findViewById(R.id.btn_take_photo);
        btn_pick_photo = (LinearLayout) mMenuView.findViewById(R.id.btn_pick_photo);
        btn_cancel     = (LinearLayout) mMenuView.findViewById(R.id.btn_cancel);

        btn_cancel.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                dismiss();  
            }
        });

        btn_pick_photo.setOnClickListener(itemsOnClick);  
        btn_take_photo.setOnClickListener(itemsOnClick);

        this.setContentView(mMenuView);
        this.setWidth(LayoutParams.FILL_PARENT);
        this.setHeight(LayoutParams.WRAP_CONTENT);
        this.setFocusable(true);

        ColorDrawable dw = new ColorDrawable(0xb0000000);
        this.setBackgroundDrawable(dw);
        mMenuView.setOnTouchListener(new OnTouchListener() {  
              
            public boolean onTouch(View v, MotionEvent event) {
                int height = mMenuView.findViewById(R.id.pop_layout).getTop();  
                int y= (int) event.getY();  
                if(event.getAction() == MotionEvent.ACTION_UP)
                    if(y < height)  
                        dismiss();      
                return true;  
            }  
        });  
  
    }  
  
}  